package com.fjec.market.mapper.sqlbuilder;

import java.util.List;

public class PurchasingSqlBuilder {
    public String get2PurchasingByPurchaseIds(final List<Long> purchaseIds) {
        if (purchaseIds.size() == 0) return null;
        StringBuilder sb = new StringBuilder();
        purchaseIds.forEach(id ->
                sb.append(" union all select * from (select purchasing.* from biz_purchasing purchasing where purchasing.PurcId = ")
                .append(id).append(" and (purchasing.ValidPeriodNum = 999 or purchasing.ValidPeriod >= NOW() - INTERVAL 1 DAY ) limit 0, 2) tmp")
                .append(id));
        return sb.delete(0, 11).toString();
    }

    public String getPurchasingByPurchaseIds(final List<Long> purchaseIds) {
        if (purchaseIds.size() == 0) return null;
        StringBuilder sb = new StringBuilder();
        purchaseIds.forEach(id ->
                sb.append(" union all select * from (select purchasing.* from biz_purchasing purchasing where purchasing.PurcId = ")
                        .append(id).append(" and (purchasing.ValidPeriodNum = 999 or purchasing.ValidPeriod >= NOW() - INTERVAL 1 DAY ) ) tmp")
                        .append(id));
        return sb.delete(0, 11).toString();
    }
}
